import * as constants from './constants'
// Immutable对象不可被变更
// fromJS可以帮我们把JS对象转换成Immutable对象
import {fromJS} from "immutable";

const defaultState = fromJS({
    focused: false,
    mouseIn: false,
    list: [],
    page: 1,
    totalPage: 1
});
export default (state = defaultState, action) => {
    switch (action.type) {
        case constants.SEARCH_BLUR:
            //immutable对象的set方法,会结合之前immutable对象的值和设置的值，返回一个全新的对象
            return state.set('focused', false);
        case constants.SEARCH_FOCUS:
            return state.set('focused', true);
        case constants.CHANGE_LIST:
            //merge接收一个对象，可以同时改变多个immutable数据
            return  state.merge({
                list:action.data,
                totalPage: action.totalPage
            });
            // return state.set('list', action.data).set('totalPage', action.totalPage);
        case constants.MOUSE_ENTER:
            return state.set('mouseIn', true);
        case constants.MOUSE_LEAVE:
            return state.set('mouseIn', false);
        case constants.CHANGE_PAGE:
            return state.set('page', action.page);
        default:
            return state;
    }
}
